package cn.xz.gobang.service;

import static android.content.ContentValues.TAG;

import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.yanzhenjie.andserver.annotation.GetMapping;
import com.yanzhenjie.andserver.annotation.PostMapping;
import com.yanzhenjie.andserver.annotation.RequestParam;
import com.yanzhenjie.andserver.annotation.RestController;

import cn.xz.gobang.bean.CommonLib;
import cn.xz.gobang.bean.EventBusMessage;
import cn.xz.gobang.bean.RoomSingle;
import cn.xz.gobang.util.EventBusUtils;
import cn.xz.gobang.util.GetDataUtils;
import cn.xz.gobang.util.JsonUtil;


@RestController
public class UserController {

    //测试连接用户
    @PostMapping(CommonLib.GET_TEST)
    String login(@RequestParam("f_ip") String f_ip) {
        Log.i(TAG, "login: 收到消息");
        CommonLib.mFriends.add(f_ip);
        EventBusUtils.INSTANCE.postEvent(new EventBusMessage(CommonLib.INSTANCE.GET_USER_DATA,f_ip));
        return "在线";
    }

    @GetMapping("/test1")
    String test() {
        return "ok";
    }

    //被邀请者进入房间
    @GetMapping("/open")
    String open() {
        EventBusUtils.INSTANCE.postEvent(new EventBusMessage(CommonLib.INSTANCE.OPEN_PLAY,""));
        return "ok";
    }

    //获取下棋数据
    @GetMapping(CommonLib.GET_ALL_USER)
    String getTxt() {
        String mR = "";
        if (CommonLib.mData != null){
            mR = JSONObject.toJSONString(CommonLib.mData) ;
        }
        return mR;
    }
}
